home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 7 #1
/
IMG Vol 7-1.iso
/
Updaters
/
InputSprocket 1.3
/
Sample Drivers
/
ISp Sample ADB Sources
/
ISpSampleADB.h
< prev
next >
Wrap
Text File
|
1998-04-15
|
6KB
|
280 lines
/*************************************************************************************
File: ISpSampleADB.h
Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
You may incorporate this sample code into your applications without
restriction, though the sample code has been provided "AS IS" and the
responsibility for its operation is 100% yours. However, what you are
not permitted to do is to redistribute the source as "DSC Sample Code"
after having made changes. If you're going to re-distribute the source,
we require that you make it clear in the source that the code was
descended from Apple Sample Code, but that you've made changes.
*************************************************************************************/
#ifndef __ISPSAMPLEADB__
#define __ISPSAMPLEADB__
#ifndef __TYPES__
#include <Types.h>
#endif
#ifndef __DESKBUS__
#include <DeskBus.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#ifndef __INPUTSPROCKET__
#include <InputSprocket.h>
#endif
#include "ISpPlugInUI.h"
#include "InputSprocketDefer.h"
#include "ISpSampleADBRes.h"
class SidewinderPro : public ISpPlugInUI
{
public:
SidewinderPro(ADBAddress inADBAddr, const FSSpec &inFileSpec);
~SidewinderPro();
public:
// these must be overridden in the subclass
OSStatus Init( UInt32 count,
ISpNeed needs[],
ISpElementReference virtualElements[],
Boolean used[],
OSType appCreatorCode,
OSType subCreatorCode,
UInt32 reserved,
void* reserved2);
OSStatus Stop(void);
OSStatus GetSize(Point &minimum, Point &best);
OSStatus HandleEvent(EventRecord &theEvent, Boolean &handled);
OSStatus Show(DialogPtr theDialog, short dialogItemNumber, Rect &r);
OSStatus Hide(void);
OSStatus BeginConfiguration(UInt32 count, ISpNeed needs[]);
OSStatus EndConfiguration(Boolean accept);
OSStatus GetIcon(short &iconSuiteResourceId);
OSStatus GetState(UInt32 buflen, void *buffer, UInt32 &length);
OSStatus SetState(UInt32 length, void *buffer);
OSStatus SetActive(Boolean active);
OSStatus DialogItemHit(short itemHit);
OSStatus Tickle(void);
OSStatus InterruptTickle(void);
OSStatus Draw(void);
OSStatus Click(const EventRecord &event);
OSStatus ADBReInit(Boolean inPostProcess);
public:
static OSStatus Initialize(FSSpec fileSpec);
static Boolean IsSideWinder(short inDeviceTableIndex);
static void Terminate(void);
void AutoConfigure(Boolean used[]);
private:
static SidewinderPro *gSidewinders[16];
private:
OSStatus CreateDevice(void);
OSStatus DisposeDevice(void);
OSStatus Patch(void);
OSStatus Unpatch(void);
public:
void ParseData(
void *inBuffer,
UInt32 inCommand);
public:
// virtual element code
void StartVirtualElements(void);
void StopVirtualElements(void);
UInt32 * GetDialogItemToNeedMapping () { return mDialogItemToNeedMapping; };
private:
UInt32 mDialogItemToNeedMapping[kDialogItem_NumPopups+1]; // we dont use index 0
public:
enum
{
kTrigger = 0,
kTopButton,
kStickHighButton,
kStickLowButton,
kBaseFarLeft,
kBaseFarRight,
kBaseNearLeft,
kBaseNearRight,
kNumSidewinderButtons
};
private:
typedef struct
{
UInt32 xAxis;
UInt32 yAxis;
UInt32 throttle;
UInt32 rudder;
UInt32 hat;
UInt32 buttons[kNumSidewinderButtons];
} SidewinderStateStruct;
typedef struct
{
// axis
UInt32 xAxis;
UInt32 yAxis;
UInt32 throttle;
UInt32 rudder;
UInt32 xAxis_as_buttons[2];
UInt32 yAxis_as_buttons[2];
UInt32 throttle_as_buttons[2];
UInt32 rudder_as_buttons[2];
// hat
UInt32 hat;
UInt32 hat_as_buttons[4]; // t,l,b,r
UInt32 hat_as_axis[2]; // x,y
// buttons
UInt32 buttons[kNumSidewinderButtons];
} HighLevelData;
SidewinderStateStruct mOldState;
HighLevelData mOldHLData;
// this function looks at mOldState to set some things up
#if !__MWERKS__
inline
#endif
void StateToHighLevelData(const SidewinderStateStruct &inState, HighLevelData& outHLData);
void SetAsFields(HighLevelData ¤t);
void PushDataToVirtuals(HighLevelData ¤t);
// reverse
Boolean mReverseStickVertical;
Boolean mReverseHatVertical;
Boolean mReverseRudder;
Boolean mReverseThrottle;
private:
short mWhichDevice;
// actual elements, nil if doesn't exist
ISpDeviceReference mDevice;
ISpElementReference mXAxis;
ISpElementReference mYAxis;
ISpElementReference mThrottle;
ISpElementReference mRudder;
ISpElementReference mHat;
ISpElementReference mButtons[kNumSidewinderButtons];
private:
// ui code, internal
// internal
Boolean mVisable;
Boolean mActive;
volatile Boolean mVirtualElementsValid;
void SetVirtualElements(void);
Boolean IsPressed (short inDialogItem); // is this dialog item 'pressed' (ie on the device)
Boolean mPopupPressed[kDialogItem_NumPopups];
void UpdateSingleButton(UInt32 curButton, UInt32 index);
void UpdateAllButtons(void);
private:
typedef struct
{
// axis
ISpElementReference xAxis;
ISpElementReference yAxis;
ISpElementReference throttle;
ISpElementReference rudder;
ISpElementReference stickMovement;
ISpElementReference stickDPad;
ISpElementReference xAxis_as_buttons[2];
ISpElementReference yAxis_as_buttons[2];
ISpElementReference throttle_as_buttons[2];
ISpElementReference rudder_as_buttons[2];
// hat
ISpElementReference hat;
ISpElementReference hat_as_movement;
ISpElementReference hat_as_buttons[4]; // t,l,b,r
ISpElementReference hat_as_axis[2]; // x,y
// buttons
ISpElementReference buttons[kNumSidewinderButtons];
} VirtualElements;
VirtualElements mVirtuals;
private:
void ClearVirtuals (void);
OSStatus PushAllNonDefaultValues(void);
private:
FSSpec mFileSpec;
Rect mRect;
short mResRef;
typedef struct
{
UInt32 version;
UInt32 mapping[kDialogItem_NumPopups];
UInt32 flags;
} MicrosoftSetVersion1;
enum
{
kSetReverseStickVertical = 0x00000001,
kSetReverseHatVertical = 0x00000002,
kSetReverseThrottle = 0x00000004,
kSetReverseRudder = 0x00000008
};
enum
{
kSetVersion1 = '0002'
};
private:
Boolean mOrphan;
ADBAddress mADBAddress;
Boolean mMustRestorePatch;
Boolean mPatched;
ISpADBDeferRef mADBDefer;
private:
void DoReverse(short dialog_item, Boolean &the_boolean);
};
#endif // SAMPLEADB